var number = 10;
var startingPage;

function Open_Data(sellerID) {
    var sellerState = 2;
    var data = {
        "sellerID": sellerID,
        "sellerState": sellerState
    };
    swal.fire({
        type: 'warning', // 弹框类型
        title: '确认', //标题
        text: "确认关闭商户账号", //显示内容
        confirmButtonColor: '#3085d6',// 确定按钮的 颜色
        confirmButtonText: '确定',// 确定按钮的 文字
        showCancelButton: true, // 是否显示取消按钮
        cancelButtonColor: '#d33', // 取消按钮的 颜色
        cancelButtonText: "取消", // 取消按钮的 文字
        focusCancel: true, // 是否聚焦 取消按钮
        reverseButtons: true  // 是否 反转 两个按钮的位置 默认是  左边 确定  右边 取消
    }).then(function (isConfirm) {
        if (isConfirm.value) {
            $.ajax({
                url: "updateSellerBySellerState",
                type: "POST",
                dataType: "json",
                contentType: 'application/json;charset=utf-8',
                data: JSON.stringify(data),
                async: false,
                success: function (data) {
                    if (data.code == 200) {
                        Swal.fire("提示", "商户账号关闭成功", "success");
                    } else {
                        Swal.fire("提示", "商户账号关闭失败", "error");
                    }
                }
            });
            loadWebList();
        } else {
            Swal.fire("提示", "已取消提交", "error");
        }
    })
}

function Close_Data(sellerID) {
    var sellerState = 1;
    var data = {
        "sellerID": sellerID,
        "sellerState": sellerState
    };
    swal.fire({
        type: 'warning', // 弹框类型
        title: '确认', //标题
        text: "确认启动商户账号", //显示内容
        confirmButtonColor: '#3085d6',// 确定按钮的 颜色
        confirmButtonText: '确定',// 确定按钮的 文字
        showCancelButton: true, // 是否显示取消按钮
        cancelButtonColor: '#d33', // 取消按钮的 颜色
        cancelButtonText: "取消", // 取消按钮的 文字
        focusCancel: true, // 是否聚焦 取消按钮
        reverseButtons: true  // 是否 反转 两个按钮的位置 默认是  左边 确定  右边 取消
    }).then(function (isConfirm) {
        if (isConfirm.value) {
            $.ajax({
                url: "updateSellerBySellerState",
                type: "POST",
                dataType: "json",
                contentType: 'application/json;charset=utf-8',
                data: JSON.stringify(data),
                async: false,
                success: function (data) {
                    if (data.code == 200) {
                        Swal.fire("提示", "商户账号启动成功", "success");
                    } else {
                        Swal.fire("提示", "商户账号启动失败", "error");
                    }
                }
            });
            loadWebList();
        } else {
            Swal.fire("提示", "已取消提交", "error");
        }
    })
}

//初始数据
function loadWebList() {
    startingPage = 0;
    var data = {
        "page": startingPage,
        "number": number
    };
    $.ajax({
        url: "findSellerBySellerList",
        type: "POST",
        dataType: "json",
        data: JSON.stringify(data),
        contentType: 'application/json;charset=utf-8',
        success: function (data) {
            var code = ' ';
            if (data.code == 500) {
                Swal.fire("提示", "查询数据失败", "error");
            } else {
                for (var i = 0; i < data.user_List.length; i++) {
                    if (data.user_List[i].sellerState == 1) {
                        code += "  <tr>\n" +
                            "                            <td>" + (i + 1) + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerNickname + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerName + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerSex + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerPhone + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerAddress + "</td>\n" +
                            "                            <td class=\"td-status\">\n" +
                            "                                <span class=\"layui-btn layui-btn-normal layui-btn-mini\">已启用</span>\n" +
                            "                            </td>\n" +
                            "                            <td class=\"td-manage\">\n" +
                            "                                <a onclick=\"Open_Data(" + data.user_List[i].sellerID + ",this)\" href=\"javascript:;\" title=\"启用\">\n" +
                            "                                    <i class=\"layui-icon\">&#xe601;</i>\n" +
                            "                                </a>\n" +
                            "                            </td>\n" +
                            "                        </tr>"
                    } else {
                        code += "  <tr>\n" +
                            "                            <td>" + (i + 1) + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerNickname + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerName + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerSex + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerPhone + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerAddress + "</td>\n" +
                            "                            <td class=\"td-status\">\n" +
                            "                                <span class=\"layui-btn layui-btn-danger\">已禁用</span>\n" +
                            "                            </td>\n" +
                            "                            <td class=\"td-manage\">\n" +
                            "                                <a onclick=\"Close_Data(" + data.user_List[i].sellerID + ",this)\" href=\"javascript:;\" title=\"启用\">\n" +
                            "                                    <i class=\"layui-icon\">&#xe601;</i>\n" +
                            "                                </a>\n" +
                            "                            </td>\n" +
                            "                        </tr>"
                    }

                }
                $("#SellerData").html(code);
                $("#pageNumber").val(data.count);
                $("#myProjectTable").html(" <a class=\"prev\"  onclick='myProjectTable_previous()'>&lt;&lt;</a> <span class=\"current\">" + (startingPage + 1) + "</span><a class=\"next\" onclick='myProjectTable_next()'>&gt;&gt;</a>");
            }
        }
    });
}

//上一页
function myProjectTable_previous() {
    startingPage = startingPage - 1;
    if (startingPage < 0) {
        startingPage = 0;
        Swal.fire("提示", "数据不存在", "warning");
    } else {
        var data = {
            "page": startingPage * number,
            "number": number
        };
        $.ajax({
            url: "findSellerBySellerList",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(data),
            contentType: 'application/json;charset=utf-8',
            success: function (data) {
                var code = ' ';
                if (data.code == 500) {
                    Swal.fire("提示", "查询数据失败", "error");
                } else {
                    for (var i = 0; i < data.user_List.length; i++) {
                        if (data.user_List[i].sellerState == 1) {
                            code += "  <tr>\n" +
                                "                            <td>" + (i + 1) + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerNickname + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerName + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerSex + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerPhone + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerAddress + "</td>\n" +
                                "                            <td class=\"td-status\">\n" +
                                "                                <span class=\"layui-btn layui-btn-normal layui-btn-mini\">已启用</span>\n" +
                                "                            </td>\n" +
                                "                            <td class=\"td-manage\">\n" +
                                "                                <a onclick=\"Open_Data(" + data.user_List[i].sellerID + ",this)\" href=\"javascript:;\" title=\"启用\">\n" +
                                "                                    <i class=\"layui-icon\">&#xe601;</i>\n" +
                                "                                </a>\n" +
                                "                            </td>\n" +
                                "                        </tr>"
                        } else {
                            code += "  <tr>\n" +
                                "                            <td>" + (i + 1) + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerNickname + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerName + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerSex + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerPhone + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerAddress + "</td>\n" +
                                "                            <td class=\"td-status\">\n" +
                                "                                <span class=\"layui-btn layui-btn-danger\">已禁用</span>\n" +
                                "                            </td>\n" +
                                "                            <td class=\"td-manage\">\n" +
                                "                                <a onclick=\"Close_Data(" + data.user_List[i].sellerID + ",this)\" href=\"javascript:;\" title=\"启用\">\n" +
                                "                                    <i class=\"layui-icon\">&#xe601;</i>\n" +
                                "                                </a>\n" +
                                "                            </td>\n" +
                                "                        </tr>"
                        }

                    }
                    $("#SellerData").html(code);
                    $("#pageNumber").val(data.count);
                    $("#myProjectTable").html(" <a class=\"prev\"  onclick='myProjectTable_previous()'>&lt;&lt;</a> <span class=\"current\">" + (startingPage + 1) + "</span><a class=\"next\" onclick='myProjectTable_next()'>&gt;&gt;</a>");
                }
            }
        });
    }
}

//下一页
function myProjectTable_next() {
    startingPage = startingPage + 1;
    var startingPageNumber = startingPage * number;
    var numberSum = $("#pageNumber").val();
    if (startingPageNumber > numberSum && (startingPageNumber - number) < numberSum) {
        startingPage = startingPage - 1;
        Swal.fire("提示", "数据浏览已到底", "warning");
    } else {
        var data = {
            "page": startingPageNumber,
            "number": number
        };
        $.ajax({
            url: "findSellerBySellerList",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(data),
            contentType: 'application/json;charset=utf-8',
            success: function (data) {
                var code = ' ';
                if (data.code == 500) {
                    Swal.fire("提示", "查询数据失败", "error");
                } else {
                    for (var i = 0; i < data.user_List.length; i++) {
                        if (data.user_List[i].sellerState == 1) {
                            code += "  <tr>\n" +
                                "                            <td>" + (i + 1) + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerNickname + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerName + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerSex + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerPhone + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerAddress + "</td>\n" +
                                "                            <td class=\"td-status\">\n" +
                                "                                <span class=\"layui-btn layui-btn-normal layui-btn-mini\">已启用</span>\n" +
                                "                            </td>\n" +
                                "                            <td class=\"td-manage\">\n" +
                                "                                <a onclick=\"Open_Data(" + data.user_List[i].sellerID + ",this)\" href=\"javascript:;\" title=\"启用\">\n" +
                                "                                    <i class=\"layui-icon\">&#xe601;</i>\n" +
                                "                                </a>\n" +
                                "                            </td>\n" +
                                "                        </tr>"
                        } else {
                            code += "  <tr>\n" +
                                "                            <td>" + (i + 1) + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerNickname + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerName + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerSex + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerPhone + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerAddress + "</td>\n" +
                                "                            <td class=\"td-status\">\n" +
                                "                                <span class=\"layui-btn layui-btn-danger\">已禁用</span>\n" +
                                "                            </td>\n" +
                                "                            <td class=\"td-manage\">\n" +
                                "                                <a onclick=\"Close_Data(" + data.user_List[i].sellerID + ",this)\" href=\"javascript:;\" title=\"启用\">\n" +
                                "                                    <i class=\"layui-icon\">&#xe601;</i>\n" +
                                "                                </a>\n" +
                                "                            </td>\n" +
                                "                        </tr>"
                        }

                    }
                    $("#SellerData").html(code);
                    $("#pageNumber").val(data.count);
                    $("#myProjectTable").html(" <a class=\"prev\"  onclick='myProjectTable_previous()'>&lt;&lt;</a> <span class=\"current\">" + (startingPage + 1) + "</span><a class=\"next\" onclick='myProjectTable_next()'>&gt;&gt;</a>");
                }
            }
        });
    }
}

//模糊初始数据
function loadWebList_1() {
    startingPage = 0;
    var searchName = $("#searchName").val();
    var data = {
        "page": startingPage,
        "number": number,
        "sellerName": searchName
    };
    $.ajax({
        url: "findSellerBySellerConcatList",
        type: "POST",
        dataType: "json",
        data: JSON.stringify(data),
        contentType: 'application/json;charset=utf-8',
        success: function (data) {
            var code = ' ';
            if (data.code == 500) {
                Swal.fire("提示", "查询数据失败", "error");
            } else {
                for (var i = 0; i < data.user_List.length; i++) {
                    if (data.user_List[i].sellerState == 1) {
                        code += "  <tr>\n" +
                            "                            <td>" + (i + 1) + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerNickname + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerName + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerSex + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerPhone + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerAddress + "</td>\n" +
                            "                            <td class=\"td-status\">\n" +
                            "                                <span class=\"layui-btn layui-btn-normal layui-btn-mini\">已启用</span>\n" +
                            "                            </td>\n" +
                            "                            <td class=\"td-manage\">\n" +
                            "                                <a onclick=\"Open_Data(" + data.user_List[i].sellerID + ",this)\" href=\"javascript:;\" title=\"启用\">\n" +
                            "                                    <i class=\"layui-icon\">&#xe601;</i>\n" +
                            "                                </a>\n" +
                            "                            </td>\n" +
                            "                        </tr>"
                    } else {
                        code += "  <tr>\n" +
                            "                            <td>" + (i + 1) + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerNickname + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerName + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerSex + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerPhone + "</td>\n" +
                            "                            <td>" + data.user_List[i].sellerAddress + "</td>\n" +
                            "                            <td class=\"td-status\">\n" +
                            "                                <span class=\"layui-btn layui-btn-danger\">已禁用</span>\n" +
                            "                            </td>\n" +
                            "                            <td class=\"td-manage\">\n" +
                            "                                <a onclick=\"Close_Data(" + data.user_List[i].sellerID + ",this)\" href=\"javascript:;\" title=\"启用\">\n" +
                            "                                    <i class=\"layui-icon\">&#xe601;</i>\n" +
                            "                                </a>\n" +
                            "                            </td>\n" +
                            "                        </tr>"
                    }

                }
                $("#SellerData").html(code);
                $("#pageNumber").val(data.count);
                $("#myProjectTable").html(" <a class=\"prev\"  onclick='myProjectTable_previous_1()'>&lt;&lt;</a> <span class=\"current\">" + (startingPage + 1) + "</span><a class=\"next\" onclick='myProjectTable_next_1()'>&gt;&gt;</a>");
            }
        }
    });
}

//模糊初始数据上一页
function myProjectTable_previous_1() {
    startingPage = startingPage - 1;
    if (startingPage < 0) {
        startingPage = 0;
        Swal.fire("提示", "数据不存在", "warning");
    } else {
        var searchName = $("#searchName").val();
        var data = {
            "page": startingPage,
            "number": number,
            "sellerName": searchName
        };
        $.ajax({
            url: "findSellerBySellerConcatList",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(data),
            contentType: 'application/json;charset=utf-8',
            success: function (data) {
                var code = ' ';
                if (data.code == 500) {
                    Swal.fire("提示", "查询数据失败", "error");
                } else {
                    for (var i = 0; i < data.user_List.length; i++) {
                        if (data.user_List[i].sellerState == 1) {
                            code += "  <tr>\n" +
                                "                            <td>" + (i + 1) + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerNickname + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerName + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerSex + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerPhone + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerAddress + "</td>\n" +
                                "                            <td class=\"td-status\">\n" +
                                "                                <span class=\"layui-btn layui-btn-normal layui-btn-mini\">已启用</span>\n" +
                                "                            </td>\n" +
                                "                            <td class=\"td-manage\">\n" +
                                "                                <a onclick=\"Open_Data(" + data.user_List[i].sellerID + ",this)\" href=\"javascript:;\" title=\"启用\">\n" +
                                "                                    <i class=\"layui-icon\">&#xe601;</i>\n" +
                                "                                </a>\n" +
                                "                            </td>\n" +
                                "                        </tr>"
                        } else {
                            code += "  <tr>\n" +
                                "                            <td>" + (i + 1) + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerNickname + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerName + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerSex + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerPhone + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerAddress + "</td>\n" +
                                "                            <td class=\"td-status\">\n" +
                                "                                <span class=\"layui-btn layui-btn-danger\">已禁用</span>\n" +
                                "                            </td>\n" +
                                "                            <td class=\"td-manage\">\n" +
                                "                                <a onclick=\"Close_Data(" + data.user_List[i].sellerID + ",this)\" href=\"javascript:;\" title=\"启用\">\n" +
                                "                                    <i class=\"layui-icon\">&#xe601;</i>\n" +
                                "                                </a>\n" +
                                "                            </td>\n" +
                                "                        </tr>"
                        }

                    }
                    $("#SellerData").html(code);
                    $("#pageNumber").val(data.count);
                    $("#myProjectTable").html(" <a class=\"prev\"  onclick='myProjectTable_previous_1()'>&lt;&lt;</a> <span class=\"current\">" + (startingPage + 1) + "</span><a class=\"next\" onclick='myProjectTable_next_1()'>&gt;&gt;</a>");
                }
            }
        });
    }
}

//模糊初始数据下一页
function myProjectTable_next_1() {
    startingPage = startingPage + 1;
    var startingPageNumber = startingPage * number;
    var numberSum = $("#pageNumber").val();
    if (startingPageNumber > numberSum && (startingPageNumber - number) < numberSum) {
        startingPage = startingPage - 1;
        Swal.fire("提示", "数据浏览已到底", "warning");
    } else {
        var searchName = $("#searchName").val();
        var data = {
            "page": startingPage,
            "number": number,
            "sellerName": searchName
        };
        $.ajax({
            url: "findSellerBySellerConcatList",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(data),
            contentType: 'application/json;charset=utf-8',
            success: function (data) {
                var code = ' ';
                if (data.code == 500) {
                    Swal.fire("提示", "查询数据失败", "error");
                } else {
                    for (var i = 0; i < data.user_List.length; i++) {
                        if (data.user_List[i].sellerState == 1) {
                            code += "  <tr>\n" +
                                "                            <td>" + (i + 1) + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerNickname + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerName + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerSex + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerPhone + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerAddress + "</td>\n" +
                                "                            <td class=\"td-status\">\n" +
                                "                                <span class=\"layui-btn layui-btn-normal layui-btn-mini\">已启用</span>\n" +
                                "                            </td>\n" +
                                "                            <td class=\"td-manage\">\n" +
                                "                                <a onclick=\"Open_Data(" + data.user_List[i].sellerID + ",this)\" href=\"javascript:;\" title=\"启用\">\n" +
                                "                                    <i class=\"layui-icon\">&#xe601;</i>\n" +
                                "                                </a>\n" +
                                "                            </td>\n" +
                                "                        </tr>"
                        } else {
                            code += "  <tr>\n" +
                                "                            <td>" + (i + 1) + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerNickname + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerName + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerSex + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerPhone + "</td>\n" +
                                "                            <td>" + data.user_List[i].sellerAddress + "</td>\n" +
                                "                            <td class=\"td-status\">\n" +
                                "                                <span class=\"layui-btn layui-btn-danger\">已禁用</span>\n" +
                                "                            </td>\n" +
                                "                            <td class=\"td-manage\">\n" +
                                "                                <a onclick=\"Close_Data(" + data.user_List[i].sellerID + ",this)\" href=\"javascript:;\" title=\"启用\">\n" +
                                "                                    <i class=\"layui-icon\">&#xe601;</i>\n" +
                                "                                </a>\n" +
                                "                            </td>\n" +
                                "                        </tr>"
                        }

                    }
                    $("#SellerData").html(code);
                    $("#pageNumber").val(data.count);
                    $("#myProjectTable").html(" <a class=\"prev\"  onclick='myProjectTable_previous_1()'>&lt;&lt;</a> <span class=\"current\">" + (startingPage + 1) + "</span><a class=\"next\" onclick='myProjectTable_next_1()'>&gt;&gt;</a>");
                }
            }
        });
    }
}


$(function () {
    loadWebList();
});
